package cn.quevo.cube.provide.data.tools;

import cn.quevo.cube.provide.data.enums.SequenceFormatter;

/**
 * 日期序列格式化工具
 *
 * @author July july_sky@foxmail.com
 * @version 1.0
 * @date 2018/12/14 5:44 PM
 * @Copyright 湘豫（北京）科技有限公司版权所有.All Rights Reserved.
 */
public class SequenceFormatterTools {

    /**
     * 获取正确的格式化参数
     *
     * @param fmt
     * @return
     * @author July july_sky@foxmail.com
     * @date 2018/12/14 5:44 PM
     * @Copyright 湘豫（北京）科技有限公司版权所有.All Rights Reserved.
     */
    public static String getFormatter(String fmt) {
        return getFormatter(fmt, "");
    }

    /**
     * 根据数据库类型获取正确的格式化参数
     *
     * @param fmt
     * @param dbType
     * @return
     * @author July july_sky@foxmail.com
     * @date 2018/12/14 5:45 PM
     * @Copyright 湘豫（北京）科技有限公司版权所有.All Rights Reserved.
     */
    public static String getFormatter(String fmt, String dbType) {
        dbType = dbType == null ? "" : dbType;
        SequenceFormatter formatter = null;
        try {
            formatter = SequenceFormatter.valueOf((dbType + "_" + fmt).toUpperCase());
        } catch (Exception e) {
            formatter = SequenceFormatter.valueOf(fmt.toUpperCase());
        }
        return formatter.getCode();
    }
}
